import { reactive, onMounted } from 'vue';
import axios from 'axios';

export default function() {
  // 数据
  let catList = reactive([])

  // 方法
  async  function getCat() {
    try {
      let result = await axios.get('https://api.thecatapi.com/v1/images/search?limit=1')
      console.log(result.data)
      catList.push(...result.data.map(obj => obj.url))
    } catch(error) {
      console.log(error)
      alert(error)
    }
  }

  onMounted(() => getCat())
  return {catList, getCat}
}

